<?php
/**
 * MKSyslogRoute class file
 *
 * @author ZhangJinlong <zhangjinlong@pwrd.com>
 * @link http://www.mk-style.com/
 * @copyright Copyright &copy; 2012 C&C Media
 */

class SyslogRoute extends CLogRoute
{
	private $_ident;
	private $_option;
	private $_facility;

	/**
	 * (non-PHPdoc)
	 * @see CLogRoute::init()
	 */
	public function init()
	{
	    parent::init();
	}

	/**
	 * 获得IDENT
	 */
	public function getIdent()
	{
	    return $this->_ident;
	}

	/**
	 * 设置IDENT
	 * @param unknown_type $ident
	 */
	public function setIdent($ident)
	{
	    $this->_ident = $ident;
	}

	/**
	 * 获得OPTION
	 */
	public function getOption()
	{
	    return $this->_option;
	}

	/**
	 * 设置OPTION
	 * @param unknown_type $option
	 */
	public function setOption($option)
	{
	    $this->_option = $option;
	}

	/**
	 * 获得FACILITY
	 */
	public function getFacility()
	{
	    return $this->_facility;
	}

	/**
	 * 设置FACILITY
	 * @param unknown_type $facility
	 */
	public function setFacility($facility)
	{
	    $this->_facility = $facility;
	}

	/**
	 * (non-PHPdoc)
	 * @see CLogRoute::processLogs()
	 */
	protected function processLogs($logs)
	{
	    openlog($this->ident, $this->option, $this->facility);

	    foreach ($logs as $log)
	    {
	        $priority = NULL;

	        switch ($log['1'])
	        {
	            case CLogger::LEVEL_INFO:
	                $priority = LOG_INFO;
	                break;

	            case CLogger::LEVEL_WARNING:
	                $priority = LOG_WARNING;
	                break;

                case CLogger::LEVEL_ERROR:
                    $priority = LOG_ERR;
                    break;

                default:
                    $priority = LOG_NOTICE;
                    break;
	        }

	        syslog($priority, $this->formatLogMessage($log[0], $log[1], $log[2], $log[3]));
	    }
	}

	/**
	 * 析构方法
	 */
	public function __destruct()
	{
	    closelog();
	}
}